import type { AccountItem } from "@/api/access/accounts";
import type { RoleItem } from "@/api/access/roles";
import type { PermissionNode } from "@/api/access/permissions";
import type { OrgTreeNode } from "@/api/access/org";

const now = () => new Date().toISOString().slice(0, 19).replace("T", " ");

export const getFallbackAccounts = (): AccountItem[] => [
  {
    id: 1,
    username: "admin",
    nickname: "平台管理员",
    real_name: "平台管理员",
    phone: "13800000000",
    email: "admin@example.com",
    status: 1,
    org_id: 0,
    org_name: "总部",
    created_at: now(),
    updated_at: now(),
    roles: [
      {
        id: 1,
        name: "管理员",
        code: "admin"
      }
    ]
  },
  {
    id: 2,
    username: "ops-user",
    nickname: "运营人员",
    real_name: "运营人员",
    phone: "13900000001",
    email: "ops@example.com",
    status: 1,
    org_id: 1,
    org_name: "华东运营中心",
    created_at: now(),
    updated_at: now(),
    roles: [
      {
        id: 2,
        name: "运营",
        code: "operations"
      }
    ]
  }
];

export const getFallbackRoles = (): RoleItem[] => [
  {
    id: 1,
    name: "管理员",
    code: "admin",
    slug: "admin",
    status: 1,
    description: "系统超级管理员，拥有全部权限",
    created_at: now(),
    permissions: ["system:config:view", "system:menu:edit"],
    permission_ids: [2, 3]
  },
  {
    id: 2,
    name: "运营",
    code: "operations",
    slug: "operations",
    status: 1,
    description: "运营人员，可管理商品与交易",
    created_at: now(),
    permissions: ["product:manage", "order:review"],
    permission_ids: [5]
  }
];

export const getFallbackPermissions = (): PermissionNode[] => [
  {
    id: 1,
    parent_id: null,
    name: "系统管理",
    code: "system",
    type: "menu",
    client_type: "admin",
    status: 1,
    sort: 10,
    children: [
      {
        id: 2,
        parent_id: 1,
        name: "配置查看",
        code: "system:config:view",
        type: "action",
        client_type: "admin",
        status: 1,
        sort: 11
      },
      {
        id: 3,
        parent_id: 1,
        name: "菜单编辑",
        code: "system:menu:edit",
        type: "action",
        client_type: "admin",
        status: 1,
        sort: 12
      }
    ]
  },
  {
    id: 4,
    parent_id: null,
    name: "交易管理",
    code: "order",
    type: "menu",
    client_type: "admin",
    status: 1,
    sort: 20,
    children: [
      {
        id: 5,
        parent_id: 4,
        name: "订单审核",
        code: "order:review",
        type: "action",
        client_type: "admin",
        status: 1,
        sort: 21
      }
    ]
  }
];

export const getFallbackOrgTree = (): OrgTreeNode[] => [
  {
    id: 0,
    name: "全部组织",
    parent_id: null,
    type: "root",
    children: [
      {
        id: 1,
        name: "华东运营中心",
        parent_id: 0,
        type: "branch",
        children: [
          {
            id: 3,
            name: "上海运营组",
            parent_id: 1,
            type: "team"
          }
        ]
      },
      {
        id: 2,
        name: "华南运营中心",
        parent_id: 0,
        type: "branch"
      }
    ]
  }
];
